#install.packages("openxlsx")
#install.packages("readxl")
#install.packages("leaflet")
#install.packages("sf")
#install.packages("dplyr")
#install.packages("ggplot2")
#install.packages("giscoR")
#install.packages("scales")
#install.packages("quarto")CellTowers
library(leaflet);library(sf)Linking to GEOS 3.13.1, GDAL 3.11.0, PROJ 9.6.0; sf_use_s2() is TRUE
library(ggplot2);library(dplyr)
Adjuntando el paquete: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(units);library(htmlwidgets)udunits database from C:/Users/marc/AppData/Local/R/win-library/4.5/units/share/udunits/udunits2.xml
library(giscoR);library(rnaturalearthdata)
library(scales);library(rnaturalearth)
Adjuntando el paquete: 'rnaturalearth'
The following object is masked from 'package:rnaturalearthdata':
countries110
library(plotly);library(quarto)
Adjuntando el paquete: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
df2 <- read.csv("C:/Users/marc/Desktop/UOC/DataViz/P2/Africa towers.csv")
#rm(df2)df_egypt <- df2[df2$Country == "Egypt", ]df_egypt <- df_egypt[df_egypt$LON >= 30 & df_egypt$LON <= 33.2, ]
df_egypt <- df_egypt[, !(names(df_egypt) %in% c("created", "updated", "averageSignal", "Continent", "changeable"))]# Load river data from Natural Earth
rivers <- ne_download(scale = 10,
type = "rivers_lake_centerlines",
category = "physical",
returnclass = "sf")Reading layer `ne_10m_rivers_lake_centerlines' from data source
`C:\Users\marc\AppData\Local\Temp\RtmpWoDagI\ne_10m_rivers_lake_centerlines.shp'
using driver `ESRI Shapefile'
Simple feature collection with 1473 features and 38 fields
Geometry type: MULTILINESTRING
Dimension: XY
Bounding box: xmin: -164.9035 ymin: -52.15775 xmax: 177.5204 ymax: 75.79348
Geodetic CRS: WGS 84
# Filter all segments related to the Nile system
nile_parts <- rivers %>%
filter(name %in% c(
"Nile"
))
# Combine into a single multiline geometry
nile <- st_union(nile_parts)
# Convert towers to sf points (keeping original LAT and LON)
towers_sf <- st_as_sf(df_egypt, coords = c("LON", "LAT"), crs = 4326, remove = FALSE)
# Reproject both geometries to metric CRS for distance computation
towers_proj <- st_transform(towers_sf, 3857)
nile_proj <- st_transform(nile, 3857)
# Filter towers within 10 km of the Nile
nearby_index <- st_is_within_distance(towers_proj, nile_proj, dist = 10000)
towers_near_nile <- towers_proj[lengths(nearby_index) > 0, ]
# Drop geometry but keep original columns
towers_near_nile_df <- st_drop_geometry(towers_near_nile)leaflet(data = towers_near_nile_df) %>%
addTiles() %>%
addCircleMarkers(
lng = ~LON,
lat = ~LAT,
radius = ~5,
color = "blue",
stroke = FALSE,
fillOpacity = 0.3,
popup = ~paste("Radio:", radio,
"<br>Operador (mcc):", MCC,
"<br>Net:", Network,
"<br>Rango (m):", RANGE)
) %>%
setView(lng = 31, lat = 26.5, zoom = 6) leaflet(data = towers_near_nile_df) %>%
addTiles() %>%
# Add subtle range coverage circles
addCircles(
lng = ~LON,
lat = ~LAT,
radius = ~RANGE,
color = "#FFA500", # lighter orange
stroke = FALSE, # remove border
fillOpacity = 0.05 # very transparent
) %>%
# Add sharp tower markers
addCircleMarkers(
lng = ~LON,
lat = ~LAT,
radius = 5,
color = "black",
fillColor = "cyan",
stroke = TRUE,
weight = 0.8,
fillOpacity = 0.9,
popup = ~paste("Radio:", radio,
"<br>Operador (mcc):", MCC,
"<br>Net:", Network,
"<br>Rango (m):", RANGE)
) %>%
setView(lng = 31, lat = 26.5, zoom = 8)